﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Content;

namespace XNAVE3D
{
    class PlansManager //: Microsoft.Xna.Framework.DrawableGameComponent
    {
        int NUM_PLANOS = 19;

        List<Plano> plans = new List<Plano>();

        Effect effect;

        //public PlansManager(Game game)
            //: base(game)
        public PlansManager(ContentManager Content)
        {
            //effect = Game.Content.Load<Effect>("Effects/Effect1");
            effect = Content.Load<Effect>("Effects/Effect1");

            for (int i = 0; i < NUM_PLANOS; i++)
            {
                Plano a = null;
                plans.Add(a);
            }

            // casa
            plans[0] = new Plano(new Vector3(10, 3.5f, -16), Content.Load<Texture2D>("Texturas/TexturaMadeira"), null, new Vector3(10, 4.5f, 0), effect, false);
            plans[1] = new Plano(new Vector3(10, 3.5f, 10), Content.Load<Texture2D>("Texturas/TexturaMadeiraPorta"), null, new Vector3(10, 4.5f, 0), effect, false);
            plans[2] = new Plano(new Vector3(20, 3.5f, -3), Content.Load<Texture2D>("Texturas/TexturaMadeiraJanela"), null, new Vector3(0, 4.5f, 13), effect, false);
            plans[3] = new Plano(new Vector3(0, 3.5f, -3), Content.Load<Texture2D>("Texturas/TexturaMadeiraJanela"), null, new Vector3(0, 4.5f, 13), effect, false);

            // teto casa
            plans[4] = new Plano(new Vector3(10, 8, -3), Content.Load<Texture2D>("Texturas/Telha"), null, new Vector3(10, 0, 13), effect, false);

            // paredes moinho 1
            plans[5] = new Plano(new Vector3(-12, 8, -17), Content.Load<Texture2D>("Texturas/TexturaMadeira"), null, new Vector3(2, 10, 0), effect, false);
            plans[6] = new Plano(new Vector3(-12, 8, -13), Content.Load<Texture2D>("Texturas/TexturaMadeira"), null, new Vector3(2, 10, 0), effect, false);
            plans[7] = new Plano(new Vector3(-10, 8, -15), Content.Load<Texture2D>("Texturas/TexturaMadeira"), null, new Vector3(0, 10, 2), effect, false);
            plans[8] = new Plano(new Vector3(-14, 8, -15), Content.Load<Texture2D>("Texturas/TexturaMadeira"), null, new Vector3(0, 10, 2), effect, false);

            // teto moinho 2
            plans[9] = new Plano(new Vector3(-12, 18, -15), Content.Load<Texture2D>("Texturas/TelhadoMoinho"), null, new Vector3(2, 0, 2), effect, false);

            // helices 
            plans[10] = new Plano(new Vector3(-9.99f, 15, -15), Content.Load<Texture2D>("Texturas/TexturaTelhado"), null, new Vector3(0, 1, 7), effect, false);
            plans[11] = new Plano(new Vector3(-9.99f, 15, -15), Content.Load<Texture2D>("Texturas/TexturaTelhado"), null, new Vector3(0, 7, 1), effect, false);

            // paredes moinho 2
            plans[12] = new Plano(new Vector3(30, 8, -17), Content.Load<Texture2D>("Texturas/TexturaMadeira"), null, new Vector3(2, 10, 0), effect, false);
            plans[13] = new Plano(new Vector3(30, 8, -13), Content.Load<Texture2D>("Texturas/TexturaMadeira"), null, new Vector3(2, 10, 0), effect, false);
            plans[14] = new Plano(new Vector3(32, 8, -15), Content.Load<Texture2D>("Texturas/TexturaMadeira"), null, new Vector3(0, 10, 2), effect, false);
            plans[15] = new Plano(new Vector3(28, 8, -15), Content.Load<Texture2D>("Texturas/TexturaMadeira"), null, new Vector3(0, 10, 2), effect, false);

            // teto moinho 2
            plans[16] = new Plano(new Vector3(30, 18, -15), Content.Load<Texture2D>("Texturas/TelhadoMoinho"), null, new Vector3(2, 0, 2), effect, false);

            // helices 2
            plans[17] = new Plano(new Vector3(27.99f, 15, -15), Content.Load<Texture2D>("Texturas/TexturaTelhado"), null, new Vector3(0, 1, 7), effect, false);
            plans[18] = new Plano(new Vector3(27.99f, 15, -15), Content.Load<Texture2D>("Texturas/TexturaTelhado"), null, new Vector3(0, 7, 1), effect, false);
            
            // chao
            //plans[19] = new Plano(new Vector3(0, -2, 0), Game.Content.Load<Texture2D>(@"Texturas/TexturaGrama"), Game.Content.Load<Texture2D>(@"Texturas/neve"), new Vector3(150, 0, 150), effect, true);
            //plans[19] = new Plano(new Vector3(30, -2, 150), Game.Content.Load<Texture2D>(@"Texturas/Info"), Game.Content.Load<Texture2D>(@"Texturas/neve"), new Vector3(50, 0, 20), effect, false);

        }

        //public override void Update(GameTime gameTime)
        public void Update(GameTime gameTime)
        {
            plans[10].myWorld *= Matrix.CreateRotationX(MathHelper.ToRadians(4));
            plans[11].myWorld *= Matrix.CreateRotationX(MathHelper.ToRadians(4));
            plans[17].myWorld *= Matrix.CreateRotationX(MathHelper.ToRadians(4));
            plans[18].myWorld *= Matrix.CreateRotationX(MathHelper.ToRadians(4));
            foreach (Plano a in plans)
            {
                a.Update(gameTime);
            }

            //base.Update(gameTime);
        }

        public void Draw(GameTime gameTime, Matrix view, Matrix projection, GraphicsDevice graphicsDevice)
        {
            //tem que ficar assim pq está desenhado com as orientações erradas: 
            graphicsDevice.RasterizerState = RasterizerState.CullNone;

            foreach (Plano a in plans)
            {
                a.Draw(view, projection, graphicsDevice);
            }

            //depois devolve ao padrão senão todo o resto tá desenhado com o lado de dentro tb, performance...
            graphicsDevice.RasterizerState = RasterizerState.CullCounterClockwise;
        }

    }
}
